package pers.ree.demo.concurrent.atomic;

import java.util.concurrent.atomic.AtomicStampedReference;

public class AtomicStampedReferenceDemo {

    public static void main(String[] args) {

        int stamp = (int) System.currentTimeMillis() / 1000;

        AtomicStampedReference atomicStampedReference = new AtomicStampedReference(2, stamp);

        // false， value比较不通过
        System.out.println(atomicStampedReference.compareAndSet(1, 3, stamp, stamp));

        // false，stamp比较不通过
        System.out.println(atomicStampedReference.compareAndSet(1, 3, stamp, stamp));

        // true
        System.out.println(atomicStampedReference.compareAndSet(2, 3, stamp, stamp));
    }
}
